package com.example.listener;

import com.example.entity.UserEntity;
import com.iogogogo.activity.domain.dto.ActivityDTO;
import com.iogogogo.activity.message.ActivityMessage;
import com.iogogogo.activity.util.ExtendBeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created by tao.zeng on 2022/6/15.
 */
@Slf4j
@Component
public class ActivityMessageListener implements ApplicationListener<ActivityMessage> {

    @Override
    public void onApplicationEvent(ActivityMessage event) {
        Object object = event.getSource();

        log.info("object ==> {}", object);

        if (object instanceof ActivityDTO) {
            ActivityDTO<?, ?> activity = (ActivityDTO<?, ?>) object;

            Map<?, ?> map = (Map<?, ?>) activity.getSource();

            UserEntity userEntity = ExtendBeanUtils.mapToBean(map, UserEntity.class);

            log.info("userEntity ===> {}", userEntity);
        }
    }
}
